#!/usr/bin/perl 

use strict;

use DBI;
use CGI;
use TTraker;

my $dbh;
initialize_dbi();
print_header();

my $form_ref = &parse_input;
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $cliId = $FORM_DATA{'cliId'};
my $cliFac = $FORM_DATA{'cliFac'};
my $cliName = $FORM_DATA{'cliName'};
my $cliCat = $FORM_DATA{'cliCat'};
my $cliAct = $FORM_DATA{'cliAct'};
my $msg = "";
my $sw;

if ( $cliFac > 0 && $cliFac < 6 ) {
	# do nothing
} else { 	
	$msg = "FACILITY MUST BE 1, 2, 3, 4, OR 5";
	$sw += 1;
}	
if ( $cliCat =~ /\D/ ) {
	$msg = "REVENUE CODE MUST BE A NUMBER PRFERABLY 0, 5, OR 10";
	$sw += 2;
}	
if ( $cliAct eq "y" || $cliAct eq "Y" ) {
	$cliAct == "Y";
} elsif ( $cliAct eq "n" || $cliAct eq "N" ) {
	$cliAct == "N";
} else {
	$msg = "ACTIVE MUST BE Y or N!";
	$sw += 3;
}
if ( $sw == 0 ) {
	change_client_info ($cliId, $cliFac, $cliName, $cliCat, $cliAct);
	adm_activity_screen_from_pm ($num,$name,$job,$loc);
} else {
	refresh_update_client_data_screen_msg ($num, $name, $cliId, $cliFac, $cliName, $cliCat, $cliAct, $msg); 
}

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub refresh_update_client_data_screen_msg
{
	my $num = $_[0];
	my $name = $_[1];
	my $cliId = $_[2];
	my $cliFac = $_[3];
	my $cliName = $_[4];
	my $cliCat = $_[5];
	my $cliAct = $_[6];
	my $msg = $_[7];
	
print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_adm_add_new_client.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  &nbsp&nbsp&nbsp&nbsp&nbsp
  <div id = "box5_1"> 
  <h3>Update Client Information</h3>
  </div>
<form id="box2_0" autocomplete="off" name="empID" action="${cgi_ref}trak_04_adm_update_client_data.pl" method="post">
  <input type="hidden" name="empName" value='$name'/>
  <input type="hidden" name="empNum" value='$num'/>
  <input type="hidden" name="cliId" value='$cliId'/>
  <table>
	<tr>
  		<td>Client ID:<td/>
		<td id="warn">$cliId<td/> 
	<tr/>
	<tr>
  		<td>Facility #:<td/>
  		<td><input type="text" size=2 value="$cliFac" name=cliFac /><td/>
  	<tr/>
  	<tr>
  		<td>Name:<td/>
  		<td><input type="text" size=30 value="$cliName" name=cliName /><td/>
	<tr/>
	<tr>	
  		<td>Revenue Code: &nbsp&nbsp<td/>
  		<td><input type="text" size=2 value="$cliCat" name=cliCat /><td/>
	<tr/>
	<tr>	
  		<td>Active:<td/>
  		<td><input type="text" size=2 value="$cliAct" name=cliAct /><td/>
	<tr/>
	<table/>
   <br/><br/><br/>
   <input type="submit" value="Update Information">
   <br/><br/><br/>
   <a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
   <br/><br/>
	<b id="info">$msg</b>
   <br/><br/>
 </form>
 </div>
 </body>
 </html>
ENDHEADER
}





